// Copyright (C) 2011 YANG Hao (yangh2007@gmail.com). All rights reserved.
//
// This file is part of the (cute)octopus project.
//
// This file may be distributed and/or modified under the terms of the
// GNU General Public License version 2 as published by the Free Software
// Foundation.
//
// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
//
// Author(s): YANG Hao

#ifndef OCREATOR_H
#define OCREATOR_H

#include <QtPlugin>
#include <QObject>
#include <QIcon>
#include <QString>
#include <QAction>
#include "ostd.h"

class OAction;
class ODoc;
class OTaskAsync;
class ODocDescriptor;

typedef QList<OTask*>	OTaskList;
typedef QList<OAction*> OActionList;
typedef QList<ODocDescriptor*> OFileDescriptorList;

class OCTOPUS_EXPORT OCreator : public QObject
{
public:
	OCreator(const OFileDescriptorList& fds, const OTaskList& tasks, const OActionList& actions);
	virtual ~OCreator();

public:
	virtual ODoc* createDoc(const QString& filePath) = 0;
	virtual QWidget* createWidget(const QString& descriptor, ODoc* doc) = 0;

	inline const ODocDescriptor* mainFormat() const {return m_formatList.first();}
	inline QList<ODocDescriptor*> formats() const {return m_formatList;}
	inline QString filters() const {return m_filters;}
	inline ODocDescriptor* format(const QString& suffix) {return m_formatMap.value(suffix);}

	inline OTaskList tasks() const {return m_tasks;}
	
	inline QStringList toolBarNames() const {return m_toolBarNames;}
	inline QStringList menuNames() const {return m_menuNames;}
	inline OActionList actions() const {return m_actions;}

	virtual void widgetActivated(QWidget* w) {}
	virtual QString name() const {return QObject::tr("An Octopus Creator");}
	virtual QIcon icon() const {return O_DEVELOP_ICON;}

	QVariant tryProperty(const char* name, const QVariant& v);

protected:
	QMap<QString, ODocDescriptor*> m_formatMap;
	OFileDescriptorList m_formatList;
	QString m_filters;

	OTaskList m_tasks;

	QStringList m_toolBarNames, m_menuNames;
	OActionList m_actions;
};

#endif // OCREATOR_H
